#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int Partition(vector<int> & arr, int i, int j)
{
	int left = i, right = j;
	int keyi = i;
	while (left < right) 
	{
		while (left < right && arr[right] > arr[keyi])
			right--;
		while (left < right && arr[left] <= arr[keyi])
			left++;
		swap(arr[left], arr[right]);
	}
	swap(arr[left], arr[keyi]);

	return left;
}

void QuickSort(vector<int>& arr, int i, int j)
{
	if (i < j)
	{
		int mid = Partition(arr, i, j);
		for (auto x : arr)
			cout << x << " ";
		cout << endl;
		QuickSort(arr, i, mid - 1);
		QuickSort(arr, mid+1,j);
	}
	return;
}

int main()
{
	int n;
	cin >> n;
	vector<int> arr(n);
		
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	QuickSort(arr, 0, n-1);
	for (auto x : arr)
		cout << x << " ";

	return 0;
}